<!DOCTYPE html>
<html>
<head>
    <meta charset='UTF-8'>
    <title>天气案例</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h2>今天天气{{info}}</h2>
        <!-- @xxx="yyy" yyy可以写一些简单的语句 -->
        <!-- <button @click="isHot = !isHot">切换天气</button> -->
        <button @click="changeWeather">切换天气</button>
        <hr/>
    
    </div>
</body>
<!--   JS   -->
    <script>
        const vm = new Vue({
            el:'#root',
            data:{
                isHot:true,
            },
            computed:{
                info(){
                    return this.isHot?'炎热':'凉爽'
                }
            },
            methods: {
                changeWeather(){
                     this.isHot = !this.isHot
                }
            },
            watch:{
                //完整写法
                /* isHot:{
                    //immediate:true,//初始化时调用handler
                    //isHot发生改变时
                    handler(newValue,oldValue){
                        console.log('ishot修改了',newValue,oldValue)
                    }
                } */
                //简写
                /* isHot(newValue,oldValue){
                    console.log('ishot修改了',newValue,oldValue)
                } */
            }
        })
        vm.$watch('isHot',function(newValue,oldValue){
            console.log('ishot修改了',newValue,oldValue)
        })
    </script>
</html>